<?php 
if ($action == "add") {
	$insertSQL = sprintf("INSERT INTO readings 
		(
		cid,
		mid,
		reading_material, 
		reading_assignment,
		reading_notes
		) 
		VALUES 
		(%s, %s, %s, %s, %s)", 	
			GetSQLValueString($cid, "int"),
			GetSQLValueString($mid, "int"),
			GetSQLValueString($_POST['reading_material'], "int"),
			GetSQLValueString($_POST['reading_assignment'], "text"),
			GetSQLValueString($_POST['reading_notes'], "text")
			);
					
	mysql_select_db($database, $connection);
	$result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
	//echo $insertSQL."<br>";
	$insertGoTo = "../index.php?section=view_course&cid=".$cid."&msg=1#".$mid;
	header(sprintf("Location: %s", $insertGoTo));
}
	
if ($action == "edit") {
	$updateSQL = sprintf("UPDATE readings
		SET 
		cid=%s,
		mid=%s,
		reading_material=%s, 
		reading_assignment=%s,
		reading_notes=%s
		WHERE id=%s", 
			GetSQLValueString($cid, "int"),
			GetSQLValueString($mid, "int"),
			GetSQLValueString($_POST['reading_material'], "int"),
			GetSQLValueString($_POST['reading_assignment'], "text"),
			GetSQLValueString($_POST['reading_notes'], "text"),
			GetSQLValueString($id, "int")
		);
					
	mysql_select_db($database, $connection);
	$result1 = mysql_query($updateSQL, $connection) or die(mysql_error());
	// echo $updateSQL;
	
	$updateGoTo = "../index.php?section=view_course&cid=".$cid."&msg=2#".$mid;
	header(sprintf("Location: %s", $updateGoTo));
}


?>